package com.itheima.appserver.controller;

import com.itheima.appserver.config.MyAnno;
import com.itheima.appserver.service.UserInfoService;
import com.itheima.appserver.service.UserService;
import com.itheima.commons.pojo.UserInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.util.Map;

@RestController
@RequestMapping("/user")
public class UserController {

    @Autowired
    private UserService userService;

    @Autowired
    private UserInfoService userInfoService;

    //发送验证码
    @MyAnno
    @PostMapping("/login")
    public ResponseEntity loginSendMsg(@RequestBody Map<String,String> param){
        userService.loginSendMsg(param.get("phone"));
        return ResponseEntity.ok(null);
    }
    //提交验证码
    @MyAnno
    @PostMapping("/loginVerification")
    public ResponseEntity loginVerification(@RequestBody Map<String,String> params){
        Map<String, Object> map = userService.verificationCode(params.get("phone"), params.get("verificationCode"));
        return ResponseEntity.ok(map);
    }
    //用户信息注册
    @PostMapping("/loginReginfo")
    public ResponseEntity loginReginfo(@RequestBody Map<String,String> params){
        userInfoService.loginReginfo(params);
        return ResponseEntity.ok(null);
    }
    //修改头像
    @PostMapping("/loginReginfo/head")
    public ResponseEntity head(@RequestParam("headPhoto")MultipartFile pic){
        userInfoService.UpdateHeadPic(pic);
        return ResponseEntity.ok(null);
    }
}
